from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-04-18 14:09:58.218591
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sun, 18, Apr, 2021
Time: 14:10:03
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -47.6171
Nobs: 265.000 HQIC: -48.3443
Log likelihood: 3176.18 FPE: 6.19891e-22
AIC: -48.8328 Det(Omega_mle): 4.44154e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.440060 0.123556 3.562 0.000
L1.Burgenland 0.080853 0.061182 1.322 0.186
L1.Kärnten -0.222465 0.053732 -4.140 0.000
L1.Niederösterreich 0.078835 0.132748 0.594 0.553
L1.Oberösterreich 0.212852 0.126051 1.689 0.091
L1.Salzburg 0.271526 0.069851 3.887 0.000
L1.Steiermark 0.120185 0.088846 1.353 0.176
L1.Tirol 0.121323 0.061140 1.984 0.047
L1.Vorarlberg -0.035434 0.056386 -0.628 0.530
L1.Wien -0.057033 0.114478 -0.498 0.618
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.484632 0.144094 3.363 0.001
L1.Burgenland 0.002132 0.071352 0.030 0.976
L1.Kärnten 0.328414 0.062664 5.241 0.000
L1.Niederösterreich 0.070763 0.154813 0.457 0.648
L1.Oberösterreich -0.063876 0.147004 -0.435 0.664
L1.Salzburg 0.223450 0.081462 2.743 0.006
L1.Steiermark 0.105022 0.103614 1.014 0.311
L1.Tirol 0.143106 0.071302 2.007 0.045
L1.Vorarlberg 0.154324 0.065758 2.347 0.019
L1.Wien -0.435784 0.133507 -3.264 0.001
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.284527 0.062088 4.583 0.000
L1.Burgenland 0.093658 0.030744 3.046 0.002
L1.Kärnten -0.017832 0.027001 -0.660 0.509
L1.Niederösterreich 0.059222 0.066706 0.888 0.375
L1.Oberösterreich 0.282363 0.063341 4.458 0.000
L1.Salzburg 0.026204 0.035101 0.747 0.455
L1.Steiermark 0.001905 0.044646 0.043 0.966
L1.Tirol 0.072154 0.030723 2.349 0.019
L1.Vorarlberg 0.083009 0.028334 2.930 0.003
L1.Wien 0.118781 0.057526 2.065 0.039
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.217868 0.060364 3.609 0.000
L1.Burgenland 0.022109 0.029891 0.740 0.460
L1.Kärnten 0.007962 0.026251 0.303 0.762
L1.Niederösterreich 0.048086 0.064855 0.741 0.458
L1.Oberösterreich 0.401432 0.061583 6.519 0.000
L1.Salzburg 0.083164 0.034126 2.437 0.015
L1.Steiermark 0.127776 0.043406 2.944 0.003
L1.Tirol 0.050609 0.029870 1.694 0.090
L1.Vorarlberg 0.084170 0.027548 3.055 0.002
L1.Wien -0.043036 0.055929 -0.769 0.442
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.499668 0.117844 4.240 0.000
L1.Burgenland 0.094329 0.058353 1.617 0.106
L1.Kärnten 0.011236 0.051248 0.219 0.826
L1.Niederösterreich 0.002104 0.126610 0.017 0.987
L1.Oberösterreich 0.132080 0.120223 1.099 0.272
L1.Salzburg 0.059580 0.066622 0.894 0.371
L1.Steiermark 0.061745 0.084739 0.729 0.466
L1.Tirol 0.213354 0.058313 3.659 0.000
L1.Vorarlberg 0.031779 0.053779 0.591 0.555
L1.Wien -0.098458 0.109185 -0.902 0.367
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.192551 0.093639 2.056 0.040
L1.Burgenland -0.010955 0.046368 -0.236 0.813
L1.Kärnten -0.007373 0.040722 -0.181 0.856
L1.Niederösterreich 0.000871 0.100605 0.009 0.993
L1.Oberösterreich 0.410653 0.095530 4.299 0.000
L1.Salzburg 0.016207 0.052938 0.306 0.759
L1.Steiermark -0.030587 0.067333 -0.454 0.650
L1.Tirol 0.160049 0.046335 3.454 0.001
L1.Vorarlberg 0.055131 0.042733 1.290 0.197
L1.Wien 0.218533 0.086759 2.519 0.012
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.242364 0.113371 2.138 0.033
L1.Burgenland 0.017603 0.056139 0.314 0.754
L1.Kärnten -0.071052 0.049303 -1.441 0.150
L1.Niederösterreich -0.081856 0.121805 -0.672 0.502
L1.Oberösterreich 0.023176 0.115661 0.200 0.841
L1.Salzburg 0.083606 0.064093 1.304 0.192
L1.Steiermark 0.334166 0.081522 4.099 0.000
L1.Tirol 0.463696 0.056100 8.266 0.000
L1.Vorarlberg 0.147319 0.051738 2.847 0.004
L1.Wien -0.154517 0.105041 -1.471 0.141
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.184163 0.135268 1.361 0.173
L1.Burgenland 0.039882 0.066982 0.595 0.552
L1.Kärnten -0.075373 0.058826 -1.281 0.200
L1.Niederösterreich 0.130645 0.145331 0.899 0.369
L1.Oberösterreich 0.020277 0.138000 0.147 0.883
L1.Salzburg 0.200613 0.076472 2.623 0.009
L1.Steiermark 0.114822 0.097268 1.180 0.238
L1.Tirol 0.058548 0.066935 0.875 0.382
L1.Vorarlberg 0.102954 0.061731 1.668 0.095
L1.Wien 0.229809 0.125330 1.834 0.067
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.559917 0.073460 7.622 0.000
L1.Burgenland -0.023887 0.036376 -0.657 0.511
L1.Kärnten -0.022945 0.031946 -0.718 0.473
L1.Niederösterreich 0.055919 0.078925 0.709 0.479
L1.Oberösterreich 0.310782 0.074943 4.147 0.000
L1.Salzburg 0.021601 0.041530 0.520 0.603
L1.Steiermark -0.038032 0.052823 -0.720 0.472
L1.Tirol 0.085269 0.036350 2.346 0.019
L1.Vorarlberg 0.111171 0.033524 3.316 0.001
L1.Wien -0.053710 0.068063 -0.789 0.430
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.149491 0.083605 0.166085 0.223381 0.077297 0.083279 0.012647 0.154338
Kärnten 0.149491 1.000000 0.041257 0.206306 0.180485 -0.060878 0.165872 0.027737 0.302763
Niederösterreich 0.083605 0.041257 1.000000 0.237857 0.082621 0.330630 0.141389 0.029985 0.293737
Oberösterreich 0.166085 0.206306 0.237857 1.000000 0.302110 0.263409 0.091002 0.060459 0.130603
Salzburg 0.223381 0.180485 0.082621 0.302110 1.000000 0.155659 0.054103 0.088716 0.009948
Steiermark 0.077297 -0.060878 0.330630 0.263409 0.155659 1.000000 0.102028 0.096574 -0.103478
Tirol 0.083279 0.165872 0.141389 0.091002 0.054103 0.102028 1.000000 0.161218 0.146931
Vorarlberg 0.012647 0.027737 0.029985 0.060459 0.088716 0.096574 0.161218 1.000000 -0.010180
Wien 0.154338 0.302763 0.293737 0.130603 0.009948 -0.103478 0.146931 -0.010180 1.000000